package com.hjm.project.transactionReward.controller;

import java.util.List;

import com.hjm.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.transactionReward.domain.TransactionReward;
import com.hjm.project.transactionReward.service.ITransactionRewardService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 交易量奖励配置Controller
 * 
 * @author maker-platform
 * @date 2024-01-19
 */
@Controller
@RequestMapping("/transactionReward")
public class TransactionRewardController extends BaseController {
    private String prefix = "transactionReward";

    @Resource
    private ITransactionRewardService transactionRewardService;

    @RequiresPermissions("transactionReward:transactionReward:view")
    @GetMapping()
    public String transactionReward() {
        return prefix + "/transactionReward";
    }
    @GetMapping("/transactionRewards")
    public String transactionRewards() {
        return prefix + "/transactionRewards";
    }
    @GetMapping("/selectRewardActive")
    public String selectRewardActive() {
        return prefix + "/selectRewardActive";
    }

    /**
     * 查询交易量奖励配置列表
     */
    @RequiresPermissions("transactionReward:transactionReward:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransactionReward transactionReward) {
        transactionReward.setRewardType(0);
        startPage();
        List<TransactionReward> list = transactionRewardService.selectTransactionRewardList(transactionReward);
        return getDataTable(list);
    }

    @PostMapping("/lists")
    @ResponseBody
    public TableDataInfo lists(TransactionReward transactionReward) {
        transactionReward.setRewardType(1);
        startPage();
        List<TransactionReward> list = transactionRewardService.selectTransactionRewardList(transactionReward);
        return getDataTable(list);
    }

    /**
     * 导出交易量奖励配置列表
     */
    @RequiresPermissions("transactionReward:transactionReward:export")
    @Log(title = "交易量奖励配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransactionReward transactionReward) {
        transactionReward.setRewardType(0);
        List<TransactionReward> list = transactionRewardService.selectTransactionRewardList(transactionReward);
        ExcelUtil<TransactionReward> util = new ExcelUtil<TransactionReward>(TransactionReward.class);
        return util.exportExcel(list, "transactionReward");
    }

    @Log(title = "普通交易量奖励配置", businessType = BusinessType.EXPORT)
    @PostMapping("/exports")
    @ResponseBody
    public AjaxResult exports(TransactionReward transactionReward) {
        transactionReward.setRewardType(1);
        List<TransactionReward> list = transactionRewardService.selectTransactionRewardList(transactionReward);
        ExcelUtil<TransactionReward> util = new ExcelUtil<TransactionReward>(TransactionReward.class);
        return util.exportExcel(list, "transactionReward");
    }

    /**
     * 新增交易量奖励配置
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    @GetMapping("/adds")
    public String adds() {
        return prefix + "/adds";
    }

    /**
     * 新增保存交易量奖励配置
     */
    @RequiresPermissions("transactionReward:transactionReward:add")
    @Log(title = "交易量奖励配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransactionReward transactionReward) {
        transactionReward.setCreateDateTime(DateUtils.getDateTime());
        transactionReward.setRewardType(0);
        return toAjax(transactionRewardService.insertTransactionReward(transactionReward));
    }

    @PostMapping("/adds")
    @ResponseBody
    public AjaxResult addSaves(TransactionReward transactionReward) {
        transactionReward.setCreateDateTime(DateUtils.getDateTime());
        transactionReward.setRewardType(1);
        return toAjax(transactionRewardService.insertTransactionReward(transactionReward));
    }

    /**
     * 修改交易量奖励配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        TransactionReward transactionReward = transactionRewardService.selectTransactionRewardById(id);
        mmap.put("transactionReward", transactionReward);
        return prefix + "/edit";
    }
    @GetMapping("/edits/{id}")
    public String edits(@PathVariable("id") Integer id, ModelMap mmap) {
        TransactionReward transactionReward = transactionRewardService.selectTransactionRewardById(id);
        mmap.put("transactionReward", transactionReward);
        return prefix + "/edits";
    }

    /**
     * 修改保存交易量奖励配置
     */
    @RequiresPermissions("transactionReward:transactionReward:edit")
    @Log(title = "交易量奖励配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransactionReward transactionReward) {
        transactionReward.setUpdateDateTime(DateUtils.getDateTime());
        transactionReward.setRewardType(0);
        return toAjax(transactionRewardService.updateTransactionReward(transactionReward));
    }
    @PostMapping("/edits")
    @ResponseBody
    public AjaxResult editsSave(TransactionReward transactionReward) {
        transactionReward.setUpdateDateTime(DateUtils.getDateTime());
        transactionReward.setRewardType(1);
        return toAjax(transactionRewardService.updateTransactionReward(transactionReward));
    }

    /**
     * 删除交易量奖励配置
     */
    @RequiresPermissions("transactionReward:transactionReward:remove")
    @Log(title = "交易量奖励配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(transactionRewardService.deleteTransactionRewardByIds(ids));
    }
}
